package com.example.aiquestions.service.impl;

import com.example.aiquestions.entity.Paper;
import com.example.aiquestions.mapper.PaperMapper;
import com.example.aiquestions.service.PaperService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PaperServiceImpl implements PaperService {
    @Autowired
    private PaperMapper paperMapper;

    @Override
    public Paper save(Paper paper) {
        paperMapper.save(paper);
        return paper;
    }

    @Override
    public Paper update(Paper paper) {
        paperMapper.update(paper);
        return paper;
    }

    @Override
    public boolean delete(Long paperId) {
        return paperMapper.delete(paperId) > 0;
    }

    @Override
    public Paper getById(Long paperId) {
        return paperMapper.getById(paperId);
    }

    @Override
    public PageInfo<Paper> getList(Long userId, Long subjectId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Paper> papers = paperMapper.getList(userId, subjectId);
        return new PageInfo<>(papers);
    }
}
